import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

public class ArrayList_01 {

    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<String>();
        list.add("hello");
        list.add("world");
        list.add(0,"hi");

//        System.out.println(list);
//        System.out.println(list.remove("world"));
//        System.out.println(list);
//        System.out.println(list.set(1,"javaee"));
//        System.out.println(list);
//        System.out.println(list.get(1));
//        System.out.println(list.size());
//        list.clear();//清空集合
//        list.isEmpty();//是否为空，是返回true
//        list.contains("hello");//是否包含，是返回true
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
        System.out.println("----------------------------------");
        for (String a:list){
            System.out.println(a);
        }
        System.out.println("==================================");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("==================================");
        list.forEach (s-> {
                System.out.println(s);
        });
        System.out.println("==================================");
        list.forEach(System.out::println);
    }
}
